
import { constantRouter, dataRouter, userRouter, operatorRouter, adminRouter, conditionUserRouter, conditionOperatorRouter, deny } from '../router'
import router from '../router'
import store from '../store'
let routes = constantRouter

export function useaddRoute (roles, state) {
  routes = constantRouter
  if (state !== 1) {
    if (roles === 0) {
      routesData(dataRouter)
      routesData(userRouter)
      routesData(conditionUserRouter)
    } else if (roles === 1) {
      routesData(dataRouter)
      routesData(operatorRouter)
      routesData(conditionOperatorRouter)
    } else if (roles === 2) {
      routesData(adminRouter)
    } else {
      routesData(userRouter)
    }
  }

  routesData(deny)
  // 循环添加  addRoute (vue-router 建议使用的方法)
  routes.forEach(item => {
    router.addRoute(item)
  })
}
export function getAsyncRoute (roles) {
  routes = constantRouter
  return routes
}
// 追加动态路由
function routesData (result) {
  result.forEach(item => {
    routes.push(item)
  })
  return routes
}
